﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Manger_Login : System.Web.UI.Page{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.User.Identity.Name != "")
            FormsAuthentication.RedirectFromLoginPage(Page.User.Identity.Name,false);
    }
    protected void Login1_LoggedIn(object sender, EventArgs e)
    {
        SqlDataSource ds = new SqlDataSource();
        ds.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Jxzy_Database"].ToString();
        ds.SelectCommand = "select [User_MajorID],[Major_Name],[User_Name] from [zyk_Users] inner join [zyk_Majors] on [User_MajorID]=[Major_ID] where [User_ID]=@userid";
        ds.SelectParameters.Add("userid", Login1.UserName);
        DataView dv = (DataView)ds.Select(DataSourceSelectArguments.Empty);
        if (dv != null && dv.Count > 0)
        {
            HttpCookie hck = new HttpCookie("major");
            hck.Values.Add("majorid", dv[0][0].ToString());
            hck.Values.Add("majorname", HttpUtility.UrlEncode(dv[0][1].ToString()));
            hck.Values.Add("username", HttpUtility.UrlEncode(dv[0][2].ToString()));
            Response.Cookies.Add(hck);
        }
    }
}
